#include<bits/stdc++.h>

using namespace std;
long long a[100005];
int r, b;
int t,n;
long long work(int w,long long ans,int r, int b) {
    if(w == n) {
        if (a[r] == a[w]) {
            return a[w] + ans;
        } else if (a[b] == a[w]) {
            return a[w] + ans;
        } else {
            return ans;
        }
    }
    long long ans1,ans2;
    if (a[r] == a[w]) {
        ans1 = work(w+1,ans+a[w],w,b);
    } else {
        ans1 = work(w+1,ans,w,b);
    }
    if (a[b] == a[w]) {
        ans2 = work(w+1,ans+a[w],r,w);
    } else {
        ans2 = work(w+1,ans,r,w);
    }
    return max(ans1,ans2);
}
int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> t;
    while(t--) {
        cin >> n;

        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        cout << work(0,0,0,0) << endl;
    }

    return 0;
}
/*
3
3
1 2 1
4
1 2 3 4
8
3 5 2 5 1 2 1 4
*/
















